package com.huawei.appgallery.festivalanimation.particle.modifiers;

import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import com.huawei.appgallery.festivalanimation.particle.Particle;

public class OpacityModifier implements IParticleModifier {
    public static final int STABLE_STATE_ALPHA = -1;
    private float mDuration;
    private long mEndTime;
    private int mFinalValue;
    private int mInitialValue;
    private Interpolator mInterpolator;
    private long mStartTime;

    public OpacityModifier(int i, int i2, long j, long j2, Interpolator interpolator) {
        this.mInitialValue = i;
        this.mFinalValue = i2;
        this.mStartTime = j;
        this.mEndTime = j2;
        this.mDuration = (float) (this.mEndTime - this.mStartTime);
        this.mInterpolator = interpolator;
    }

    public OpacityModifier(int i, int i2, long j, long j2) {
        this(i, i2, j, j2, new LinearInterpolator());
    }

    private int getInitialAlpha(Particle particle) {
        return this.mInitialValue == -1 ? particle.mAlpha : this.mInitialValue;
    }

    private int getFinalAlpha(Particle particle) {
        return this.mFinalValue == -1 ? particle.mInitialAlpha : this.mFinalValue;
    }

    private int getValueIncrement(Particle particle) {
        return getFinalAlpha(particle) - getInitialAlpha(particle);
    }

    public void modify(Particle particle, long j) {
        if (j >= this.mStartTime && j <= this.mEndTime) {
            float initialAlpha = (float) getInitialAlpha(particle);
            particle.mAlpha = (int) ((this.mInterpolator.getInterpolation((((float) (j - this.mStartTime)) * 1.0f) / this.mDuration) * ((float) getValueIncrement(particle))) + initialAlpha);
        }
    }
}
